package com.coderman.domainservice.blogtopic.app.executor;

import com.coderman.domainservice.blogtopic.app.command.PublishBlogCmd;
import com.coderman.domainservice.blogtopic.client.dto.BlogDTO;
import com.coderman.domainservice.blogtopic.domain.convertor.BlogConvertor;
import com.coderman.domainservice.blogtopic.domain.gataway.BlogRepository;
import com.coderman.domainservice.blogtopic.infrast.dubbo.BlogCheckAdapterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Description:
 * date: 2021/3/30
 *
 * @author shenshuai
 * @version 1.0.0
 * @since JDK 1.8
 */
@Component
public class PublishBlogCmdExe {
    @Autowired
    private BlogCheckAdapterService blogCheckAdapterService;

    @Autowired
    private BlogRepository blogRepository;

    /**
     * 发布博客命令执行入口
     * @param cmd
     * @return
     * 注意这里有事务操作
     */
    //@Transactional
    public String execute(PublishBlogCmd cmd) {
        //1.数据校验
        check(cmd.getBlogDTO());
        //2.调用gataway接口,事务接口
        blogRepository.publishBlog(BlogConvertor.INSTANCE.dto2bo(cmd.getBlogDTO()));
        //3.调用博客审核接口
        blogCheckAdapterService.checkBlog(cmd.getBlogDTO());
        return "处理中";
    }
    private String check(BlogDTO blogDTO){
        return "success";
    }
}